<?php
include_once(dirname(__FILE__) . "/../../configure/configure.php");		//--> global var
include_once(dirname(__FILE__) . "/../configure/admin.config.inc.php");	//--> admin global var
include_once(dirname(__FILE__) . "/../tools/smarty/libs/Smarty.class.php");					//--> out template

include_once("impl/CategoryImpl.php");

require_once(dirname(__FILE__) . "/../controlHeader.php");					//--> system control header
require_once(dirname(__FILE__) . "/../controlOperate.php");				//-->

$oCatImpl 	= new CategoryImpl(DB_TAG_PUBLISH);		//--> Info Class


$error_message 	= '';

$oCat = $oCatImpl->getById($id);


if(isset($_POST['Submit'])){
	$oCat->parentId 	= $_POST['parentid'];
	$oCat->name 		= $_POST['name'];
	$oCat->isLeaf 		= $_POST['isLeaf'];
	$oCat->title 		= $_POST['title'];
	$oCat->descript 	= $_POST['descript'];
	$oCat->status		= $_POST['status'];
	
	if(empty($oCat->name))
		$error_message = 'class name is required.';
	else{		
		$isOk = $oCatImpl->edit($oCat);
		if($isOk){
			header("Location: ./listClass.php?menuGid=$menuGid&menuid=$menuid&id=$id");
			exit;
		}else 
			$error_message = 'edit failure.';
	}
}

$arrIsLeaf 		= array('1' => 'Yes', '0' => 'No');
$arrStatus 		= array('1' => 'Online', '0' => 'Offline');

$arrParentid = $oCatImpl->getSelect();


/*----- out html -----*/
$smarty = new Smarty();		//----- out template
$smarty->template_dir = TEMPLATE_SYS_DIR;
$smarty->compile_dir  = COMPILE_SYS_DIR;
$smarty->assign('menuGid', $menuGid);
$smarty->assign('menuid', $menuid);
$smarty->assign('id', $id);

$smarty->assign('backurl',$backurl);
$smarty->assign('error_message', $error_message);

$smarty->assign('arrIsLeaf', $arrIsLeaf);
$smarty->assign('isLeaf', $isLeaf);

$smarty->assign('arrStatus', $arrStatus);
$smarty->assign('status', $status);

$smarty->assign('arrParentid', $arrParentid);
$smarty->assign('parentId', $parentId);

$smarty->assign('oCat', $oCat);

$smarty->display('listClass_Edit.htm');
?>
